home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / msysjour / vol05 / 02 / clipbrd / viewer3.c < prev    next >
Text File  |  1990-03-01  |  8KB  |  316 lines

  1. /*
  2.  * WINDOWS CLIPBOARD VIEWER - DIALOG SOURCE CODE
  3.  *
  4.  * LANGUAGE      : Microsoft C 5.1
  5.  * MODEL         : medium
  6.  * ENVIRONMENT   : Microsoft Windows 2.1 SDK
  7.  * STATUS        : operational
  8.  *
  9.  */
  10.  
  11. #define  NOCOMM
  12.  
  13. #include <windows.h>
  14. #include <string.h>
  15.  
  16. #include "viewer.h"
  17.  
  18. /*
  19.  * Dialog( hParentWnd, lpszTemplate, lpfnDlgProc ) : BOOL
  20.  *
  21.  *   hParentWnd      handle to parent window
  22.  *   lpszTemplate    dialog box template
  23.  *   lpfnDlgProc     dialog window function
  24.  *
  25.  * This utility function displays the specified dialog box, using the
  26.  * template provided.  It automatically makes a new instance of the
  27.  * dialog box function.  Note that this function will NOT work
  28.  * correctly if an invalid or NULL parent window handle is provided.
  29.  *
  30.  */
  31.  
  32. BOOL FAR PASCAL Dialog( hParentWnd, lpszTemplate, lpfnDlgProc )
  33.  HWND      hParentWnd;
  34.  LPSTR     lpszTemplate;
  35.  FARPROC   lpfnDlgProc;
  36. {
  37.  /* local variables */
  38.  BOOL        bResult;
  39.  FARPROC     lpProc;
  40.  
  41.  /* display palette dialog box */
  42.  lpProc = MakeProcInstance( lpfnDlgProc, INSTANCE(hParentWnd) );
  43.  bResult = DialogBox( INSTANCE(hParentWnd), lpszTemplate,
  44.                       hParentWnd, lpProc );
  45.  FreeProcInstance( lpProc );
  46.  
  47.  /* return result */
  48.  return( bResult );
  49.  
  50. }
  51.  
  52. /*
  53.  * AddFormatDlgFn( hDlg, wMsg, wParam, lParam ) : BOOL ;
  54.  *
  55.  *    hDlg           handle to dialog box
  56.  *    wMsg          message or event
  57.  *    wParam         word portion of message
  58.  *    lParam         long portion of message
  59.  *
  60.  * This function is responsible for adding a new dynamic library
  61.  * to the list of supported formats.  While doing so it checks to
  62.  * make sure that the specified format is not referenced twice.
  63.  * After adding a new format, this function also updates WIN.INI to
  64.  * reference the dynamic library.
  65.  *
  66.  */
  67.  
  68. BOOL FAR PASCAL AddFormatDlgFn(
  69.  HWND        hDlg,
  70.  WORD        wMsg,
  71.  WORD        wParam,
  72.  LONG        lParam )
  73. {
  74.  BOOL      bResult;
  75.  
  76.  /* initialization */
  77.  bResult = TRUE;
  78.  
  79.  /* process message */
  80.  switch( wMsg )
  81.    {
  82.  case WM_INITDIALOG :
  83.    CenterPopup( hDlg, GetParent(hDlg) );
  84.    EnableWindow( GetDlgItem(hDlg,IDADD), FALSE );
  85.    break;
  86.  case WM_COMMAND :
  87.  
  88.    /* process sub-message */
  89.    switch( wParam )
  90.      {
  91.    case IDCANCEL :
  92.      EndDialog( hDlg, FALSE );
  93.      break;
  94.    case IDADD :
  95.      {
  96.        char    szFmt[32];
  97.        char    szLib[64];
  98.  
  99.        /* retrieve format & library names */
  100.        GetDlgItemText( hDlg, IDFORMAT, szFmt, sizeof(szFmt) );
  101.        GetDlgItemText( hDlg, IDLIBRARY, szLib, sizeof(szLib) );
  102.  
  103.        /* upshift library name */
  104.        strupr( szLib );
  105.  
  106.        /* end dialog & add library to list */
  107.        EndDialog( hDlg, TRUE );
  108.        SendMessage( GetParent(hDlg), WM_ADDFMT,
  109.                     GetClipboardFmtNumber(szFmt),
  110.                     (LONG)(LPSTR)szLib );
  111.  
  112.      }
  113.      break;
  114.    case IDFORMAT :
  115.    case IDLIBRARY :
  116.  
  117.      /* enable or disable add button */
  118.      if ( HIWORD(lParam) == EN_CHANGE )
  119. EnableWindow(GetDlgItem(hDlg,IDADD),
  120.              ( SendMessage(GetDlgItem(hDlg,IDFORMAT),
  121.                            WM_GETTEXTLENGTH,0,0L)      &&
  122.                SendMessage(GetDlgItem(hDlg,IDLIBRARY),
  123.                            WM_GETTEXTLENGTH,0,0L)
  124.              ) ? TRUE : FALSE
  125.             );
  126.  
  127.      break;
  128.    default :
  129.      bResult = FALSE;
  130.      break;
  131.    }
  132.  
  133.    break;
  134.  default :
  135.    bResult = FALSE;
  136.    break;
  137.  }
  138.  
  139.  /* return final result */
  140.  return( bResult );
  141.  
  142. }
  143.  
  144. /*
  145.  * RemFormatDlgFn( hDlg, wMsg, wParam, lParam ) : BOOL ;
  146.  *
  147.  *    hDlg          handle to dialog box
  148.  *    wMsg          message or event
  149.  *    wParam        word portion of message
  150.  *    lParam        long portion of message
  151.  *
  152.  * This function is responsible for removing the display dynamic
  153.  * library support for a particular clipboard format.  While doing
  154.  * so is automatically updates WIN.INI and the parent window
  155.  * instance variables.
  156.  *
  157.  */
  158.  
  159. BOOL FAR PASCAL RemFormatDlgFn(
  160.  HWND        hDlg,
  161.  WORD        wMsg,
  162.  WORD        wParam,
  163.  LONG        lParam )
  164. {
  165.  BOOL      bResult;
  166.  
  167.  /* initialization */
  168.  bResult = TRUE;
  169.  
  170.  /* process message */
  171.  switch( wMsg )
  172.    {
  173.  case WM_INITDIALOG :
  174.    {
  175.      WORD      wEntry;
  176.      WORD      wModules;
  177.      HWND      hWndLibList;
  178.      char *    pszEntry;
  179.      char      szList[512];
  180.  
  181.      /* center window */
  182.      CenterPopup( hDlg, GetParent(hDlg) );
  183.      EnableWindow( GetDlgItem(hDlg,IDREMOVE), FALSE );
  184.  
  185.      /* initialize dialog box */
  186.      wModules = (WORD)SendMessage( GetParent(hDlg), WM_GETFMT, 0,
  187.                                    (LONG)(LPSTR)szList );
  188.      if ( wModules > 0 ) {
  189.  
  190.        /* initialize listbox */
  191.        hWndLibList = GetDlgItem( hDlg, IDLIBLIST );
  192.        SendMessage(hWndLibList,WM_SETREDRAW, (WORD)FALSE, (LONG)0 );
  193.        SendMessage(hWndLibList,LB_RESETCONTENT, (WORD)0, (LONG)0 );
  194.  
  195.        /* retrieve and display each listed library module */
  196.        pszEntry = &szList[0];
  197.        for ( wEntry=0; wEntry<wModules; wEntry++ ) {
  198.          SendMessage( hWndLibList, LB_ADDSTRING, (WORD)0,
  199.                       (LONG)(LPSTR)pszEntry );
  200.          pszEntry += strlen(pszEntry) + 1;
  201.        }
  202.  
  203.        /* display listbox */
  204.          SendMessage(hWndLibList,WM_SETREDRAW,(WORD)TRUE,(LONG)0);
  205.        InvalidateRect( hWndLibList, (LPRECT)NULL, TRUE );
  206.  
  207.      }
  208.  
  209.    }
  210.    break;
  211.  case WM_COMMAND :
  212.  
  213.    /* process sub-message */
  214.    switch( wParam )
  215.      {
  216.    case IDLIBLIST :
  217.  
  218.      /* enable remove button if library selected */
  219.      if (HIWORD(lParam) == LBN_SELCHANGE)
  220.        EnableWindow( GetDlgItem(hDlg,IDREMOVE), TRUE );
  221.  
  222.      break;
  223.    case IDREMOVE :
  224.      {
  225.        WORD    wEntry;
  226.  
  227.        /* retrieve selected library index & notify parent */
  228.        wEntry = (WORD)SendMessage( GetDlgItem(hDlg,IDLIBLIST),
  229.                                    LB_GETCURSEL, 0, 0L );
  230.        if ( SendMessage(GetParent(hDlg),WM_REMFMT,wEntry,0L) )
  231.          EndDialog( hDlg, TRUE );
  232.  
  233.      }
  234.  
  235.      break;
  236.    case IDCANCEL :
  237.      EndDialog( hDlg, FALSE );
  238.      break;
  239.    default :
  240.      bResult = FALSE;
  241.      break;
  242.    }
  243.  
  244.    break;
  245.  default :
  246.    bResult = FALSE;
  247.    break;
  248.  }
  249.  
  250.  /* return final result */
  251.  return( bResult );
  252.  
  253. }
  254.  
  255. /*
  256.  * AboutDlgFn( hDlg, wMsg, wParam, lParam ) : BOOL ;
  257.  *
  258.  *    hDlg          handle to dialog box
  259.  *    wMsg          message or event
  260.  *    wParam        word portion of message
  261.  *    lParam        long portion of message
  262.  *
  263.  * This function is responsible for processing all the messages
  264.  * that relate to the Viewer about dialog box.  About the only
  265.  * acts this function performs is to center the dialog box and
  266.  * wait for the Ok button to be pressed.
  267.  *
  268.  */
  269.  
  270. BOOL FAR PASCAL AboutDlgFn(
  271.  HWND      hDlg,
  272.  WORD      wMsg,
  273.  WORD      wParam,
  274.  LONG      lParam )
  275. {
  276.  BOOL      bResult;
  277.  
  278.  /* warning level 3 compatibility */
  279.  lParam;
  280.  
  281.  /* initialization */
  282.  bResult = TRUE;
  283.  
  284.  /* process message */
  285.  switch( wMsg )
  286.    {
  287.  case WM_INITDIALOG :
  288.    CenterPopup( hDlg, GetParent(hDlg) );
  289.    break;
  290.  case WM_COMMAND :
  291.  
  292.    /* process sub-message */
  293.    switch( wParam )
  294.      {
  295.    case IDOK :
  296.      EndDialog( hDlg, TRUE );
  297.      break;
  298.    case IDCANCEL :
  299.      EndDialog( hDlg, FALSE );
  300.      break;
  301.    default :
  302.      bResult = FALSE;
  303.      break;
  304.    }
  305.  
  306.    break;
  307.  default :
  308.    bResult = FALSE;
  309.    break;
  310.  }
  311.  
  312.  /* return final result */
  313.  return( bResult );
  314.  
  315. }
  316.